package com.zpp.system.controller.exam;

import com.zpp.common.core.controller.BaseController;
import com.zpp.common.core.domain.Result;
import com.zpp.common.core.domain.TableDataInfo;
import com.zpp.system.domain.exam.dto.ExamAddDTO;
import com.zpp.system.domain.exam.dto.ExamEditDTO;
import com.zpp.system.domain.exam.dto.ExamQueryDTO;
import com.zpp.system.domain.exam.dto.ExamQuestionAddDTO;
import com.zpp.system.domain.exam.vo.ExamDetailVO;
import com.zpp.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理接口")  //接口分组标签
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated ExamAddDTO examAddDTO) {
        return Result.success(examService.add(examAddDTO));
    }

    @PostMapping("/questionAdd")
    public Result<Void> questionAdd(@RequestBody ExamQuestionAddDTO examQuestionAddDTO) {
        return toResult(examService.questionAdd(examQuestionAddDTO));
    }

    @DeleteMapping("/questionDelete")
    public Result<Void> questionDelete(@RequestParam("examId") Long examId, @RequestParam("questionId") Long questionId) {
        return toResult(examService.questionDelete(examId, questionId));
    }

    @GetMapping("/detail")
    public Result<ExamDetailVO> detail(@RequestParam("examId") Long examId) {
        return Result.success(examService.detail(examId));
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toResult(examService.edit(examEditDTO));
    }

    @DeleteMapping("/delete")
    public Result<Void> delete(@RequestParam("examId") Long examId){
        return toResult(examService.delete(examId));
    }

    @PutMapping("/publish")
    public Result<Void> publish(@RequestParam("examId") Long examId){
        return toResult(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    public Result<Void> cancelPublish(@RequestParam("examId") Long examId){
        return toResult(examService.cancelPublish(examId));
    }
}
